const state={
	timetableListDialog: false,
	totalCount:0,
	param:{},
	timetableList:[],
	classroomlist:[],
	teacherlist:[]
};
const getters={
	
	isShow(state) {  //方法名随意,主要是来承载变化的timetableListDialog的值
       return state.timetableListDialog
	},
	getParam(state){
		return state.param;
	},
    gettimetableList(state){
    	return state.timetableList;
	},
	getTotalCount(state){
    	return state.totalCount;
    },
    getClassroomlist(state){
   	
   	return state.classroomlist
   },
   getTeacherlist(state){
   	
   	return state.teacherlist;
   }
};

const mutations = {
	show(state) {   //自定义改变state初始值的方法，这里面的参数除了state之外还可以再传额外的参数(变量或对象);
        state.timetableListDialog = true;
    },
    hide(state) {  //同上
        state.timetableListDialog = false;
	},
	setParam(state,data){
		state.param = data;
	},
    settimetableList(state,data){
    	
    	state.timetableList=data;
	},
	setTotalCount(state,data){
    	
    	state.totalCount=data;
    },
     setClassroomlist(state,data){
    	
    	state.classroomlist=data;
    },
    setTeacherlist(state,data){
    	
    	state.teacherlist=data;
    }
};

const actions = {
	hidetimetableListPanel(context) {  //自定义触发mutations里函数的方法，context与store 实例具有相同方法和属性
		let paras = {
			currPage:1,
			pageSize:10
		}
		context.commit('setParam',paras);
        context.commit('hide');
    },
    showtimetableListPanel(context) {  //同上注释
    	
        context.commit('show');
    },
    gettimetableList(context,paras){   	
        if(!paras.currPage || !paras.pageSize){
			paras.currPage = 1;
			paras.pageSize = 10;
		}
		context.commit('setParam',paras);
    	api.courseschedulinglist(paras).then(function(data){//排课列表
    		
		 	let curTime = tool.DateToString(new Date(),"yyyy-MM-dd HH:mm");
		 	//循环课节
		 	for(let i=0; i<data.listSyllabus.list.length; i++){
		 	 	let syllabus = data.listSyllabus.list[i];
		 	 	//判断开始时间是否大于当前时间
		 	 	syllabus.isDate = (curTime<=syllabus.startTime? true : false);
		 	 	
		 	 	syllabus.classroomInfo = "没有创建教室";
		 	 	var roomId = syllabus.talkcloudRoomId;
		 	 	if(roomId) {
		 	 		//存在网络教室,获取教室信息
		 	 		api.classroomLoginInfo({roomId: roomId}).then(function(data) {
		 	 			var info = "拓课云网络教室：" +
		 	 					   "\n教师链接：" + data.info.teacherUrl +
		 	 					   "\n教师密码：" + data.info.chairmanPwd +
		 	 					   "\n学生链接：" + data.info.studentUrl +
		 	 					   "\n学生密码：" + (data.info.passwordRequired==1? data.info.confuserPwd : "无");
		 	 			syllabus.classroomInfo = info;
			    	});
		 	 	}
		 	 	
		 	}
		 	 
		 	 
		 	 context.commit('show');
			 context.commit('settimetableList',data.listSyllabus.list);
			 context.commit('setTotalCount',data.listSyllabus.totalCount);
    	})

    }
};

module.exports = {
	  namespaced:true,//用于在全局引用此文件里的方法时标识这一个的文件名
	  state,
	  getters,
	  actions,
	  mutations
}